package org.geektimes.configuration.microprofile.config.converters;

import org.eclipse.microprofile.config.spi.Converter;

public class PrioritizedConverter<T> implements Converter<T>, Comparable<PrioritizedConverter<T>>{
	
	private static final long serialVersionUID = -1380761440539990373L;

	private Converter<T> converter;
	
	private int priority;

	public PrioritizedConverter(Converter<T> converter, int priority) {
		this.converter = converter;
		this.priority = priority;
	}

	@Override
	public T convert(String value) throws IllegalArgumentException, NullPointerException {
		return this.convert(value);
	}

	@Override
	public int compareTo(PrioritizedConverter<T> o) {
		return Integer.compare(o.getPriority(), this.priority);
	}

	public Converter<T> getConverter() {
		return converter;
	}

	public void setConverter(Converter<T> converter) {
		this.converter = converter;
	}

	public int getPriority() {
		return priority;
	}

	public void setPriority(int priority) {
		this.priority = priority;
	}

}
